﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DatabaseComponent;



public partial class SupportContactsEN : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //checkSecurityAndCustomizePage();
            bindList();
        }
    }


    /// <summary>
    /// check security and customize page controls
    /// </summary>
    private void checkSecurityAndCustomizePage()
    {
        Persons mObj = GlobalVars.getCurrentPerson();

        if (mObj.GenID == -1)
            Response.Redirect("LoginEN.aspx");


        if (!mObj.lstAllRulesIDs.Contains((long)RulesEnum.Page_Help_Desc_Contacts))
            Response.Redirect("LoginEN.aspx");
    }


    /// <summary>
    /// this function will bind the list view
    /// </summary>
    private void bindList()
    {
        HelpDescContactsDB objHelpDescContactsDB = new HelpDescContactsDB(ConnectionStrings.LMS);
        List<HelpDescContacts> lstHelpDescContacts = objHelpDescContactsDB.Select("", "");

        lvHelpDescContacts.DataSource = lstHelpDescContacts;
        lvHelpDescContacts.DataBind();

        if (lvHelpDescContacts.Items.Count > 0)
        {
            Control hrNew = lvHelpDescContacts.Items[lvHelpDescContacts.Items.Count - 1].FindControl("hrNew");
            hrNew.Visible = false;
        }
    }

    protected void lvHelpDescContacts_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {

            HiddenField hf = (HiddenField)e.Item.FindControl("hdID");
            
            long HelpDescContactsID = 0;
            long.TryParse(hf.Value,out HelpDescContactsID);

            HelpDescContactsDB objHelpDescContactsDB = new HelpDescContactsDB(ConnectionStrings.LMS);
            List<HelpDescContacts> lstHelpDescContacts = objHelpDescContactsDB.getHelpDescContactsByID(HelpDescContactsID);

            if (lstHelpDescContacts.Count == 0)
                return;

            if (lstHelpDescContacts[0].FullNameAR == "")
                e.Item.FindControl("dvName").Visible = false;


            if ((lstHelpDescContacts[0].Phone1 + lstHelpDescContacts[0].Inner1)  == "")
                e.Item.FindControl("dvPhone1").Visible = false;

            if ((lstHelpDescContacts[0].Phone2 + lstHelpDescContacts[0].Inner2) == "")
                e.Item.FindControl("dvPhone2").Visible = false;


            if (lstHelpDescContacts[0].Mobile1 == "")
                e.Item.FindControl("dvMobile1").Visible = false;


            if (lstHelpDescContacts[0].Mobile2 == "")
                e.Item.FindControl("dvMobile2").Visible = false;

            if (lstHelpDescContacts[0].Email == "")
                e.Item.FindControl("dvEmail").Visible = false;
        }

    }
}
